<template>
  <div class="user-edit all-height">
    <div :style="{ maxHeight: maxHeight }" class="drawer-content all-height">
      <div class="drawer-header">
        <div class="mr16" v-show="type == '2'">添加区</div>
        <div class="mr16" v-show="type != '2'">编辑区</div>
      </div>
        <Form ref="form" :model="form" :rules="formValidate" label-position="right" :label-width="150" class="marginForm">
        <!--                <p class="drawer-title">学籍信息</p>-->
        <Row :gutter="32">

          <Col span="24">
            <FormItem label="所在院系" prop="yxmc">
              <Input v-model.lazy="form.yxmc" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="所在班级" prop="szbj">
              <Input v-model.lazy="form.szbj" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="学号" prop="xh">
              <Input v-model.lazy="form.xh" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="考生号" prop="ksh">
              <Input v-model.lazy="form.ksh" clearable maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="姓名" prop="name">
              <Input v-model.lazy="form.name" :maxlength="50"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="身份证号" prop="idCard">
              <Input v-model.lazy="form.idCard" autocomplete="off" :maxlength="50"/>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem prop="gxcode" v-if="resource === '0' || resource === '1' || resource === '2'">
              <div class="itemLabel  " slot="label" @click="clickSexCode('gxcode')">
                <span>院校名称</span>
              </div>
              <Select v-model.lazy="form.gxcode" @on-open-change="handleSelectDataSlice('gxcode', $event)" filterable
                       @on-change="handChange()">
                <Option v-for="item in yxListSelectData" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem prop="sexCode">
              <div class="itemLabel" slot="label" @click="clickSexCode('sexCode')">
                <span>性别</span>
              </div>
              <Select v-model.lazy="form.sexCode" filterable  @on-create="keyUpSearch($event, 'sexCode')">
                <Option v-for="item in sexCodeList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem prop="mzCode">
              <div class="itemLabel" slot="label" @click="clickSexCode('mzCode')">
                <span>民族</span>
              </div>
              <Select v-model.lazy="form.mzCode" filterable  @on-create="keyUpSearch($event, 'mzCode')">
                <Option v-for="item in mzList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem prop="zzmmCode">
              <div class="itemLabel" slot="label" @click="clickSexCode('zzmmCode')">
                <span>政治面貌</span>
              </div>
              <Select v-model.lazy="form.zzmmCode" filterable  @on-create="keyUpSearch($event, 'zzmmCode')">
                <Option v-for="item in zzmmList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
          <!-- <Col span="24">
            <FormItem prop="cxsy">
              <div class="itemLabel" slot="label" @click="clickSexCode('cxsy')">
                <span>城乡生源</span>
              </div>
              <Select v-model.lazy="form.cxsy" filterable  @on-create="keyUpSearch($event, 'cxsy')">
                <Option v-for="item in cxsyList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col> -->
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem prop="xlCode">
              <div class="itemLabel" slot="label" @click="clickSexCode('xlCode')">
                <span>学历</span>
              </div>
              <Select v-model.lazy="form.xlCode" filterable  @on-create="keyUpSearch($event, 'xlCode')">
                <Option v-for="item in xlList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem prop="xxxs">
              <div class="itemLabel" slot="label" @click="clickSexCode('xxxs')">
                <span>学习形式</span>
              </div>
              <Select v-model.lazy="form.xxxs" filterable  @on-create="keyUpSearch($event, 'xxxs')">
                <Option v-for="item in xxxsList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem prop="zyXsz">
              <div class="itemLabel" slot="label" @click="clickSexCode('zyXsz')">
                <span>专业</span>
              </div>
              <Select v-model.lazy="form.zyXsz" @on-open-change="handleSelectDataSlice('zyXsz', $event)" filterable
                       @on-create="keyUpSearch($event, 'zyXsz')">
                <Option v-for="item in zyList" :value="item.value" :key="item.id">{{ item.title }}</Option>
              </Select>
              <!--              <Input v-model="form.zyCode" clearable :maxlength="70" @keydown.native="keyUpSearch($event,'zyCode')"/>-->
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="专业方向" prop="zyfx">
              <Input v-model.lazy="form.zyfx" clearable :maxlength="70"/>
            </FormItem>
          </Col>

        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem prop="pyfsCode">
              <div class="itemLabel" slot="label" @click="clickSexCode('pyfs_code')">
                <span>培养方式</span>
              </div>
              <Select :placeholder="form.pyfsCodeName" v-model.lazy="form.pyfsCode" filterable  @on-create="keyUpSearch($event, 'pyfsCode')">
                <Option v-for="item in pyfsList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="定向委培或单位" prop="dxwpdw">
              <Input v-model.lazy="form.dxwpdw" clearable maxlength="20"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem prop="cxsy" label="城乡生源">
              <!-- <div class="itemLabel" slot="label">
                <span>城乡生源</span>
              </div> -->
              <Select v-model.lazy="form.cxsy" filterable  @on-create="keyUpSearch($event, 'cxsy')">
                <Option v-for="item in cxsyList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem prop="sydCode">
              <div class="itemLabel" slot="label" @click="clickSexCode('sydCode')">
                <span>生源所在地</span>
              </div>
              <Select v-model.lazy="form.sydCode" @on-open-change="handleSelectDataSlice('sydCode', $event)" filterable
                      @on-create="keyUpSearch($event, 'sydCode')" :placeholder="form.sydCodeName">
                <Option v-for="(item,index) in areaCodeListSelectData1" :value="item.value" :key="index">
                {{ item.title }}
                </Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem prop="xz">
              <div class="itemLabel" slot="label" @click="clickSexCode('xz')">
                <span>学制</span>
              </div>
              <Select v-model.lazy="form.xz" filterable  @on-create="keyUpSearch($event, 'xz')">
                <Option v-for="item in xzList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="入学时间" prop="rxsj">
              <Input v-model.lazy="form.rxsj" clearable maxlength="20"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="毕业时间" prop="bysj">
              <Input v-model.lazy="form.bysj" clearable maxlength="20"/>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem prop="sfslbCode">
              <div class="itemLabel" slot="label" @click="clickSexCode('ffslbCode')">
                <span>师范生类别</span>
              </div>
              <Select v-model.lazy="form.sfslbCode" :placeholder="form.sfslbCodeName" filterable clearable
                      @on-create="keyUpSearch($event, 'sfslbCode')">
                <Option v-for="item in sfslbList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem prop="knslbCode">
              <div class="itemLabel" slot="label" @click="clickSexCode('knslbCode')">
                <span>困难生类别</span>
              </div>
              <Select v-model.lazy="form.knslbCode" filterable
                      @on-create="keyUpSearch($event, 'knslbCode')">
                <Option v-for="item in knslbList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="高职扩招考生标志" prop="gzkzksbz">
              <Select v-model.lazy="form.gzkzksbz" filterable
                      @on-create="keyUpSearch($event, 'gzkzksbz')">
                <Option v-for="item in gzkzksbzList" :value="item.value" :key="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="分校名称" prop="fxmc">
              <Input v-model.lazy="form.fxmc" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="是否52贫困县" prop="fxmc">
              <Select v-model.lazy="form.sf52pkx">
                <Option value="0">是</Option>
                <Option value="1">否</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="贫困县所在省" prop="fxmc">
              <Input v-model.lazy="form.sheng" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="贫困县所在市" prop="fxmc">
              <Input v-model.lazy="form.shi" clearable :maxlength="70"/>
            </FormItem>
          </Col>

          <Col span="24">
            <FormItem label="入学前档案所在单位" prop="rxqdaszdw">
              <Input v-model.lazy="form.rxqdaszdw" clearable :maxlength="70"/>
            </FormItem>
          </Col>

          <Col span="24">
            <FormItem label="档案是否转入学校" prop="dasfzrxx">
              <Input v-model.lazy="form.dasfzrxx" clearable :maxlength="70"/>
            </FormItem>
          </Col>

          <Col span="24">
            <FormItem label="入学前户口所在地派出所" prop="rxqhkszdpcs">
              <Input v-model.lazy="form.rxqhkszdpcs" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="户口是否转入学校" prop="hksfzrxx">
              <Input v-model.lazy="form.hksfzrxx" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="户口所在地" prop="hkszd">
              <Select v-model.lazy="form.hkszd" filterable>
                <Option v-for="item in areaCodeList" :value="item.value" :key="item.value">{{
                    item.title
                  }}
                </Option>
              </Select>
            </FormItem>
          </Col>
            <Col span="24">
                <FormItem label="困难群体标记" prop="fxmc">
                    <Select v-model.lazy="form.knqtbj" disabled>
                        <Option :value="0">否</Option>
                        <Option :value="1">是</Option>
                    </Select>
                </FormItem>
            </Col>
        </Row>
        <Divider/>
        <p class="drawer-title">个人信息</p>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="手机号码" prop="mobile">
              <Input v-model.lazy="form.mobile" clearable :maxlength="70"/>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="出生日期" prop="cssj">
              <Input v-model.lazy="form.cssj" clearable :maxlength="20"/>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="电子邮箱" prop="email">
              <Input v-model.lazy="form.email" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="QQ号码" prop="qq">
              <Input v-model.lazy="form.qq" clearable :maxlength="70"/>
            </FormItem>
          </Col>
        </Row>

        <Row :gutter="32">
          <Col span="24">
            <FormItem prop="szdq">
              <div class="itemLabel" slot="label" @click="clickSexCode('szdq')">
                <span>所在地区</span>
              </div>
              <Select v-model.lazy="form.szdq" :placeholder="form.szdqName" @on-open-change="handleSelectDataSlice('szdq', $event)" clearable
                      filterable>
                <Option v-for="(item,index) in areaCodeListSelectData2" :key="index" :value="item.value">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>


        <Row :gutter="32">
          <Col span="24">
            <FormItem label="家庭联系人" prop="familyContact">
              <Input v-model.lazy="form.familyContact" clearable :maxlength="70"/>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="家庭联系人关系" prop="jtlxrgx">
              <Select v-model.lazy="form.jtlxrgx" clearable
                      filterable>
                <Option v-for="(item,index) in jtlxrgxList" :value="item.value" :key="index">{{ item.title }}</Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="32">
          <Col span="24">
            <FormItem label="家庭地址" prop="jtdz">
              <Input v-model.lazy="form.jtdz" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="家庭电话" prop="jtdh">
              <Input v-model.lazy="form.jtdh" clearable :maxlength="70"/>
            </FormItem>
          </Col>
          <Col span="24">
            <FormItem label="家庭邮编" prop="jtyb">
              <Input v-model.lazy="form.jtyb" clearable :maxlength="70"/>
            </FormItem>
          </Col>
        </Row>
        <Divider/>
        <p class="drawer-title">扩展字段</p>

        <FormItem label="扩展字段1" prop="kzzd1">
          <Input v-model.lazy="form.kzzd1" clearable :maxlength="70"/>
        </FormItem>

        <FormItem label="扩展字段2" prop="kzzd2">
          <Input v-model.lazy="form.kzzd2" clearable :maxlength="70"/>
        </FormItem>
        <FormItem label="扩展字段3" prop="kzzd3">
          <Input v-model.lazy="form.kzzd3" clearable :maxlength="70"/>
        </FormItem>
        <FormItem label="扩展字段4" prop="kzzd4">
          <Input v-model.lazy="form.kzzd4" clearable :maxlength="70"/>
        </FormItem>

        <FormItem label="扩展字段5" prop="kzzd5">
          <Input v-model.lazy="form.kzzd5" clearable :maxlength="70"/>
        </FormItem>
        <FormItem label="扩展字段6" prop="kzzd6">
          <Input v-model.lazy="form.kzzd6" clearable :maxlength="70"/>
        </FormItem>
        <FormItem label="扩展字段7" prop="kzzd7">
          <Input v-model.lazy="form.kzzd7" clearable :maxlength="70"/>
        </FormItem>
        <FormItem label="扩展字段8" prop="kzzd8">
          <Input v-model.lazy="form.kzzd8" clearable :maxlength="70"/>
        </FormItem>
        <FormItem label="扩展字段9" prop="kzzd9">
          <Input v-model.lazy="form.kzzd9" clearable :maxlength="70"/>
        </FormItem>
        <FormItem label="扩展字段10" prop="kzzd10">
          <Input v-model.lazy="form.kzzd10" clearable :maxlength="70"/>
        </FormItem>
      </Form>
    </div>
    <div class="br right-bottom-edit" v-show="type != '0'">
      <Button v-has="'edit'" type="primary" :loading="submitLoading" @click="submit">提交</Button>
      <Button @click="cancel">取消</Button>
    </div>
    <!--    字典弹框-->

    <!-- </Drawer> -->
    <Modal class="cust-modal" v-model.lazy="modal" :title="modalTitle" @on-ok="clickTrue">
      <Row>
        <Col span="12">
          <div class="form-item">
            <label class="form-label">代码</label>
            <Input v-model.lazy="searchValueKeyword" placeholder="请输入搜索的代码关键字"
                   @on-change="handleModalTitleSearch"/>
          </div>
        </Col>
        <Col span="12">
          <div class="form-item">
            <label class="form-label">名称</label>
            <Input v-model.lazy="searchTitleKeyword" placeholder="请输入搜索的名称关键字"
                   @on-change="handleModalTitleSearch"/>
          </div>
        </Col>
      </Row>
      <div class="w-100">
        <Table :columns="columns" :data="dataList" :scroll="scroll" @on-row-click="handleClickRow" ref="table"></Table>

      </div>

      <Row type="flex" justify="end" class="page">
        <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage"
              size="small" show-total show-elevator></Page>
      </Row>
    </Modal>
  </div>
</template>

<script>
import {getXldmzdList} from '@/api/bys/code/xldm.js';
import {addBysPersonInfo, editBysInfo} from '@/api/bys/personInfo/bys.js';
import {getDictDataByTypeAndPage} from '@/api/index';
import {validateIDCard, validateMobileNoBt} from '@/libs/validate';
import departmentTreeChoose from '@/views/my-components/xboot/department-tree-choose';
import uploadPicInput from '@/views/my-components/xboot/upload-pic-input';
import SetPassword from '@/views/my-components/xboot/set-password';
import {getByXlAndLevelPage} from '@/api/bys/code';
import Cookies from 'js-cookie';

export default {
  name: 'user',
  components: {
    departmentTreeChoose,
    uploadPicInput,
    SetPassword
  },
  props: {
    value: {
      type: Boolean,
      default: false
    },
    dataRow: {
      type: Object
    },
    type: {
      type: String,
      default: '0'
    },
    addOrEditLabelWidth: {}
  },
  data() {
    return {
      searchForm: {
        // 搜索框初始化对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        sort: 'createTime', // 默认排序字段
        order: 'desc' // 默认排序方式
      },
      total: 0,
      resource: '',
      searchTitleKeyword: '',
      searchValueKeyword: '',
      areaCodeList: [], //地区代码表
      visible: this.value,
      title: '',
      passColor: '',
      submitLoading: false,
      maxHeight: 510,
      form: {
        type: 0,
        address: [],
        sydCode: ''
      },
      formValidate: {
        // 表单验证规则
        idCard: [
          {required: true, message: '请输入身份证号', trigger: 'change'},
          {validator: validateIDCard, trigger: 'change'}
        ],

        yxmc: [{required: true, message: '请输入院系名称', trigger: 'change'}],
        ksh: [{required: true, message: '请输入考生号', trigger: 'change'}],
        xh: [{required: true, message: '请输入学号', trigger: 'change'}],
        xxxs: [{required: true, message: '请选择学习形式', trigger: 'change'}],
        zyfx: [{required: true, message: '请输入专业方向', trigger: 'change'}],
        rxsj: [{required: true, message: '请输入入学时间', trigger: 'change'}],
        bysj: [{required: true, message: '请输入毕业时间', trigger: 'change'}],
        knslbCode: [{required: true, message: '请选择困难生类别', trigger: 'change'}],
        cxsy: [{required: true, message: '请选择城乡生源', trigger: 'change'}],

        sexCode: [{required: true, message: '请选择性别', trigger: 'change'}],
        gxcode: [{required: true, message: '请输入院校名称', trigger: 'change'}],
        mzCode: [{required: true, message: '请输入民族', trigger: 'change'}],
        name: [{required: true, message: '请输入姓名', trigger: 'change'}],
        sfslbCode: [{required: true, message: '请选择师范生类别', trigger: 'change'}],

        zzmmCode: [{required: true, message: '请选择政治面貌', trigger: 'change'}],
        xlCode: [{required: true, message: '请输入学历', trigger: 'change'}],
        zyXsz: [{required: true, message: '请输入专业', trigger: 'change'}],

        pyfsCode: [{required: true, message: '请输入培养方式', trigger: 'change'}],
        sydCode: [{required: true, message: '请输入生源所在地', trigger: 'change'}],
        xz: [{required: true, message: '请输入学制', trigger: 'change'}],

        mobile: [
          // {required: true, message: "请输入手机号", trigger: "change"},
          {validator: validateMobileNoBt, trigger: 'change'}
        ],
        email: [
          // {required: true, message: "请输入邮箱地址"},
          {type: 'email', message: '邮箱格式不正确'}
        ]
      },
      // 弹框
      modal: false,
      currentModalSearch: '',
      // 弹框标题
      modalTitle: '',
      //弹框表格
      columns: [
        {
          title: '代码',
          key: 'value',
          sortable: false,
          minWidth: 150,
          align: 'center'
        },
        {
          title: '名称',
          key: 'title',
          sortable: false,
          minWidth: 150,
          align: 'center'
        }
      ],
      defultColumns: [
        {
          title: '代码',
          key: 'value',
          sortable: false,
          minWidth: 150,
          align: 'center'
        },
        {
          title: '名称',
          key: 'title',
          sortable: false,
          minWidth: 150,
          align: 'center'
        }
      ],
      xlflColumns: [
        {
          title: '学历分类',
          key: 'xlflz',
          sortable: false,
          align: 'center',
          render: (h, params) => {
            let dict = this.xlccList.find(item => item.value == params.row.xllxz).title;
            return h('div', dict ? dict : '');
          }
        },
        {
          title: '代码',
          key: 'value',
          sortable: false,
          align: 'center'
        },
        {
          title: '名称',
          key: 'title',
          sortable: false,
          align: 'center'
        }
      ],
      zyColumns: [
        {
          title: '学历分类',
          key: 'xlflz',
          sortable: false,
          align: 'center',
          render: (h, params) => {
            let dict = this.xlccList.find(item => item.value == params.row.xllxz).title;
            return h('div', dict ? dict : '');
          }
        },
        {
          title: '代码',
          key: 'zyCode',
          sortable: false,
          align: 'center'
        },
        {
          title: '专业',
          key: 'zy',
          sortable: false,
          align: 'center'
        }
      ],
      dataList: [],
      scroll: {
        y: '200px' // 表头固定的高度
      },
      modalDict: '',
      showCode: '', //双击行传递的值
      rowList: null,
      yxList: [],
      sexCodeList: [],
      mzList: [],
      zzmmList: [],
      xlccList: [],
      xlList: [],
      xxxsList: [],
      cxsyList: [],
      pyfsList: [],
      sfslbList: [],
      knslbList: [],
      gzkzksbzList: [],
      jtlxrgxList: [],
      zyList: [],
      xzList: [],

      //
      yxListSelectData: [],
      areaCodeListSelectData1: [],
      areaCodeListSelectData2: [],
      zyXszSelectData: []
    };
  },

  methods: {
    handleSelectDataSlice(key, e,v) {
      console.log(key, e,v,'asdwadaw');
      let key1, key2;
      if (key === 'gxcode') {
        key1 = 'yxListSelectData';
        key2 = 'yxList';
      } else if (key === 'zyXsz') {
        key1 = 'zyXszSelectData';
        key2 = 'zyList';
      } else if (key === 'sydCode') {
        key1 = 'areaCodeListSelectData1';
        key2 = 'areaCodeList';
      } else if (key === 'szdq') {
        // 专业
        key1 = 'areaCodeListSelectData2';
        key2 = 'areaCodeList';
      }
      if (e) {
        if (key === 'gxcode') {
          let userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
          let userroles = sessionStorage.getItem('roles')
          console.log(userroles, 'userdata')
          console.log(userInfo.gxcode, userInfo.gxmc, 'userInfo')
          if (userroles === '["ROLE_SCHOOL"]') {
            let yxList = []
            yxList.push({value: userInfo.gxcode, title: userInfo.gxmc})
            this[key1] = yxList
          } else {
            this[key1] = this[key2]
          }
        } else {
          this[key1] = this[key2];
        }

      } else {
        // 这里不能为空 得按照这个值 在this[key2] 中找到item 然后放入this[key1]
        let value = this.form[key];

        let data = this[key2].find(item => {
          return value === item.value;
        });

        if (data) {
          this[key1] = [data];
        } else {
          // 专业可能找不到
          this[key] = [];
        }
      }
    },

    handleModalTitleSearch() {
      this.handleWatchModalDictData(this.currentModalSearch);
    },
    init() {
    },
    async getXlList() {
      let res = await this.postRequest('/xldmzd/getAll');
      if (res.success) {
        this.xlList = res.result;
      }
    },

    //代码按钮
    clickSexCode(e) {
      this.showCode = e;
      this.modal = true;
      this.searchTitleKeyword = '';
      this.searchValueKeyword = '';
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 50;
      this.currentModalSearch = e;
      this.showDict(e);
    },
    showDict(e) {
      this.columns = this.defultColumns;
      if (e == 'sexCode') {
        this.modalTitle = '性别';
        this.modalDict = 'sexCode';
      } else if (e == 'gxcode') {
        this.modalTitle = '院校名称';
        this.modalDict = 'gxcode';
      } else if (e == 'mzCode') {
        this.modalTitle = '民族';
        this.modalDict = 'mzCode';
      } else if (e == 'zzmmCode') {
        this.modalTitle = '政治面貌';
        this.modalDict = 'zzmmCode';
      } else if (e == 'xlCode') {
        this.modalTitle = '学历';
        this.modalDict = 'xlCode';
        this.columns = this.xlflColumns;
      } else if (e == 'zyXsz') {
        this.modalTitle = '专业';
        this.modalDict = 'zyXsz';
        this.columns = this.zyColumns;
      } else if (e == 'xxxs') {
        this.modalTitle = '学习形式';
        this.modalDict = 'xxxs';
      } else if (e == 'pyfs_code') {
        this.modalTitle = '培养方式';
        this.modalDict = 'pyfs_code';
      } else if (e == 'xz') {
        this.modalTitle = '学制';
        this.modalDict = 'xz';
      } else if (e == 'ffslbCode') {
        this.modalTitle = '师范生类别';
        this.modalDict = 'ffslbCode';
      } else if (e == 'knslbCode') {
        this.modalTitle = '困难生类别';
        this.modalDict = 'knslbCode';
      } else if (e == 'sydCode') {
        this.modalTitle = '生源所在地';
        this.modalDict = 'sydCode';
      } else if (e == 'szdq') {
        this.modalTitle = '所在地区';
        this.modalDict = 'szdq';
      } else if (e == 'cxsy') {
        this.modalTitle = '城乡生源';
        this.modalDict = 'cxsy';
      } else if (e == 'gzkzksbz') {
        this.modalTitle = '高职扩招考生标志';
        this.modalDict = 'gzkzksbz';
      }
      this.handleWatchModalDictData(this.currentModalSearch);
    },
    handChange() {
      const selectedItem = this.yxList.find(item => item.value === this.form.gxcode);
      if (selectedItem) {
        this.form.gxmc = selectedItem.title;
      }
    },

    keyUpSearch(e, value) {
      this.showDict(value);
      if (e.keyCode == 13 || e.keyCode == 9) {
        if (value == 'sexCode') {
          this.form.sexCode = this.sexCodeList.find(item => item.value == e.target.value).title;
        } else if (value == 'gxcode') {
          this.form.gxcode = this.yxList.find(item => item.value == e.target.value).title;
        } else if (value == 'gxmc') {
          this.form.gxmc = this.yxList.find(item => item.value == e.target.value).title;
        } else if (value == 'mzCode') {
          this.form.mzCode = this.mzList.find(item => item.value == e.target.value).title;
        } else if (value == 'zzmmCode') {
          this.form.zzmmCode = this.zzmmList.find(item => item.value == e.target.value).title;
        } else if (value == 'xlCode') {
          this.form.xlCode = this.xlList.find(item => item.value == e.target.value).title;
        } else if (value == 'pyfsCode') {
          this.form.pyfsCode = this.pyfsList.find(item => item.value == e.target.value).title;
        } else if (value == 'knslbCode') {
          this.form.knslbCode = this.knslbList.find(item => item.value == e.target.value).title;
        } else if (value == 'ffslbCode') {
          this.form.ffslbCode = this.sfslbList.find(item => item.value == e.target.value).title;
        } else if (value == 'gzkzksbz') {
          this.form.gzkzksbz = this.gzkzksbzList.find(item => item.value == e.target.value).title;
        } else if (value == 'xxxs') {
          this.form.xxxs = this.xxxsList.find(item => item.value == e.target.value).title;
        } else if (value == 'zyXsz') {
          // this.form.zyCode = this.zyList.find(item => item.value == e.target.value).title
          this.form.zyXsz = this.zyList.find(item => item.value == e.target.value).title;
        } else if (value === 'sydCode') {
          this.form.sydCode = this.areaCodeListSelectData1.find(item => item.value == e.target.value).title;
        } else if (value === 'cxsy') {
          this.form.cxsy = this.cxsyList.find(item => item.value == e.target.value).title;
        }
      }
    },
    //弹框按钮
    clickTrue(row) {
      const _this = this;
      _this.modal = false;
      if(_this.showCode === 'ffslbCode'){
        _this.form['sfslbCode'] = row.value;
        _this.form['sfslbCodeName'] = row.title;
        return;
      };
      if(_this.showCode === 'pyfs_code'){
        _this.form['pyfsCode'] = row.value;
        _this.form['pyfsCodeName'] = row.title;
        return;
      };
      const form = JSON.parse(JSON.stringify(_this.form));
      form[_this.showCode] = row.value;
      form[_this.showCode+'Name'] = row.title;
      _this.$refs.form.resetFields(); // 重置表单
      _this.$nextTick(() => {
        _this.form = form;
        _this.$forceUpdate();
      });
      // console.log(_this.showCode,_this.rowList,'11112222',_this.form,_this.$refs.form);
      // if (this.showCode==="xlCode"){
      //   this.form.xlcc = this.rowList.xllxz ? this.rowList.xllxz: ""
      // }else if (this.showCode === "gxcode"){
      //   this.form['gxmc'] = this.rowList.title
      // }
      if (this.showCode == 'gxcode') {
        this.form['gxmc'] = this.rowList.title;
      }
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.handleWatchModalDictData(this.currentModalSearch);
    },
    // table
    handleClickRow(row) {
      this.rowList = row;
      this.clickTrue(row);
    },

    changePass(v, grade, strength) {
      this.form.passStrength = strength;
      this.form.password = v;
    },
    submit(e) {
      console.log(this.form, 'this.form');
      this.$refs.form.validate(valid => {
        if (valid) {
          // this.form.mobile = this.getMockMobile();
          console.log(this.form, '通过this.form');
          if (typeof this.form.birth == 'object') {
            this.form.birth = this.format(this.form.birth, 'yyyy-MM-dd');
          }
          try {
            console.log(this.form.zyXsz, 'this.form.zyXsz');
            this.form.zy = this.zyList.find(item => item.value == this.form.zyXsz).zy;
            this.form.zyCode = this.zyList.find(item => item.value == this.form.zyXsz).zyCode;
          } catch (e) {
          }
          // this.form.jb = new Date(this.form.jb).getFullYear()
          if (this.type == '1') {
            // 编辑
            this.submitLoading = true;
            editBysInfo(this.form).then(res => {
              this.submitLoading = false;
              if (res.success) {
                this.$Message.success('操作成功');
                this.$emit('on-submit', true);
                this.visible = false;
                this.cancel();
              }
            });
          } else {
            // 添加
            this.submitLoading = true;
            addBysPersonInfo(this.form).then(res => {
              this.submitLoading = false;
              if (res.success) {
                this.$Message.success('操作成功');
                this.$emit('on-submit', true);
                this.visible = false;
                this.cancel();
              }
            });
          }
        }
      });
    },
    cancel(e) {
      this.$emit('open-search', true);
    },
    setCurrentValue(value) {
      if (value === this.visible) {
        return;
      }
      if (this.type == '1') {
        this.title = '编辑用户';
        this.maxHeight = Number(document.documentElement.clientHeight - 121) + 'px';
      } else if (this.type == '2') {
        this.title = '添加用户';
        this.maxHeight = Number(document.documentElement.clientHeight - 121) + 'px';
      } else {
        this.title = '用户详情';
        this.maxHeight = '100%';
      }
      // 清空数据
      this.$refs.form.resetFields();
      if (this.type == '0' || this.type == '1') {
        // 回显数据
        let data = this.data;
        // // 部门
        // this.$refs.depTree.setData(data.department_id, data.department_title);
        // 角色
        let selectRolesId = [];
        if (data.roles) {
          data.roles.forEach(function (e) {
            selectRolesId.push(e.id);
          });
        }
        data.roleIds = selectRolesId;
        delete data.roles;
        delete data.permissions;
        // // 密码强度
        // if (data.passStrength == "弱") {
        //   this.passColor = "#ed3f14";
        // } else if (data.passStrength == "中") {
        //   this.passColor = "#faad14";
        // } else if (data.passStrength == "强") {
        //   this.passColor = "#52c41a";
        // }
        // 回显
        this.form = this.dataRow;
        console.log('最终回显结果----',this.form,this.dataRow);
      } else {
        // // 添加
        // this.$refs.depTree.setData("", "");
        // this.form = {
        //   type: 0,
        //   sex: "",
        //   address: [],
        // };
      }
      this.visible = value;
    },
    // 生成假手机号
    getMockMobile() {
      const mobilePrefix = '152';
      let mobileSuffix = '';
      for (let i = 0; i < 8; i++) {
        mobileSuffix += Math.floor(Math.random() * 10);
      }
      return mobilePrefix + mobileSuffix;
    },
    handleWatchModalDictData(e) {
      this.dataList = [];
      if (e == 'sexCode') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'sex',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      } else if (e == 'mzCode') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'ethnic',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      } else if (e == 'zzmmCode') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'political',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      } else if (e == 'xlCode') {
        getXldmzdList({...this.searchForm, xldm: this.searchValueKeyword, xl: this.searchTitleKeyword}).then(res => {
          if (res.success) {
            this.dataList = res.result.records.map(el => {
              return {
                value: el.xldm,
                title: el.xl,
                xllxz: el.xllxz
              };
            });
            this.total = res.result.total;
          }
        });
      } else if (e == 'zyXsz') {
        getByXlAndLevelPage({
          ...this.searchForm,
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.records.map(el => {
              return {
                xllxz: el.gradLevelDict,
                value: el.profCode + el.title,
                title: el.profCode + el.title,
                zy: el.title,
                zyCode: el.profCode
              };
            });
            this.total = res.result.total;
          }
        });
      } else if (e == 'gzkzksbz') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'higher-voc-ex-exam',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      } else if (e == 'xxxs') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'learning-forms',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      } else if (e == 'pyfs_code') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'training-methods',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      } else if (e == 'xz') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'educational-system',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      } else if (e == 'ffslbCode') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'sfs_type',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      } else if (e == 'knslbCode') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'difficult-student-category',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      } else if (e == 'sydCode') {
        this.postRequest('/areaCode/getByPage', {
          ...this.searchForm,
          code: this.searchValueKeyword,
          displayName: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.records.map(e => {
              return {value: e.code, title: e.displayName};
            });
            this.total = res.result.total;
          }
        });
      } else if (e == 'szdq') {
        this.postRequest('/areaCode/getByPage', {
          ...this.searchForm,
          code: this.searchValueKeyword,
          displayName: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.records.map(e => {
              return {value: e.code, title: e.displayName};
            });
            this.total = res.result.total;
          }
        });
      }  else if (e == 'gxcode') {
        this.postRequest('/schoolCode/getByPage', {
          ...this.searchForm,
          code: this.searchValueKeyword,
          name: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.records.map(e => {
              return {value: e.code, title: e.name};
            });
            this.total = res.result.total;
          }
        });
      } else if (e == 'cxsy') {
        getDictDataByTypeAndPage({
          ...this.searchForm,
          type: 'cxsy',
          value: this.searchValueKeyword,
          title: this.searchTitleKeyword
        }).then(res => {
          if (res.success) {
            this.dataList = res.result.content;
            this.total = res.result.totalElements;
          }
        });
      }
    }
  },
  watch: {
    data(val) {
      this.setCurrentValue(val);
    },
    visible(value) {
      // if(value){
      //   this.form={}
      // }
      this.$emit('input', value);
    },
    modalDict(e) {
      return this.handleWatchModalDictData(e);
    }
  },
  mounted() {
    console.log(this);
    let resource = JSON.parse(Cookies.get('userInfo')).resource;
    this.init();
  },
  destroyed() {
  }
};
</script>
<style lang="less" scoped>
.mr16 {
  margin-right: 16px;
}

.cust-modal {
  /deep/ .ivu-modal {
    width: 30% !important;
  }
}

/deep/ .ivu-select-dropdown {
  //display: none;
}

.form-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  margin-right: 15px;
}

.form-label {
  margin-right: 10px;
  width: 40px;
}

.page {
  margin-top: 20px;
}

/deep/ .ivu-select-arrow {
  display: none;
}

@import './../../personInfo.less';

.ivu-form-item {
  margin-bottom: 0.1rem;
}

.ivu-input-prefix {
  top: 0.03rem;
}

.itemLabel {
  display: inline-block;

  span {
    color: rgb(55, 140, 254) !important;
    cursor: pointer;
  }
}

.selected {
  background-color: #f5f7fa;
}

.modalTable {
  width: 100%;

  thead {
    width: 100%;

    tr {
      width: 100%;

      th {
        width: 50%;
      }
    }
  }

  tbody {
    width: 100%;

    tr {
      width: 100%;
    }
  }
}

/deep/ .ivu-table {
  .ivu-table-body {
    height: 450px !important;
    overflow-y: scroll;

    .ivu-table-row {
      &:hover {
        .ivu-input {
          background: rgb(235, 247, 70);
        }
      }
    }

    .ivu-input {
      border: none !important;
      cursor: default;

      &:hover {
        border: none !important;
        background: rgb(235, 247, 70);
      }
    }
  }
}
// 重构样式
/deep/ .ivu-form-item-label{
    display: flex;
    justify-content: right;
    width: 150px !important;
}
/deep/ .ivu-form-item {
    margin-bottom: 0.1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
/deep/ .ivu-form-item-content {
    width: 100% !important;
    margin-left: 0 ! important;
}
/deep/ .ivu-select {
    width: 100% !important;
}
</style>
<style lang="less" scoped>
@import '../../../styles/drawer-common.less';
@import '../../personInfo.less';

.ivu-form-item-label {
  display: flex;
}

.ivu-form-item {
  margin-bottom: 0.1rem;
}

.form-label {
  margin-right: 10px;
  width: 40px;
}

.form-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  margin-right: 15px;
}

.ivu-input-prefix {
  top: 0.03rem;
}


</style>
